<?php
class Controller_News extends Controller_Abstract
{
	function actionIndex()
	{
		$cateid = intval($this->_context->cid);
		$cateid = $cateid?$cateid:105;
		$pagesize = 12;
		$page = intval($this->_context->page)?intval($this->_context->page):1;
		$pagination = NULL;
		$param_array = $this->get_param();
		# 加载分类信息
		$cateOBJ = Categorys::find('model = 1 and id = ?',$cateid)->getOne();
		if (!$cateOBJ->id()) header('location:'.url('news'));
		# 加载列表信息
		$default_find_string = "model = 1 and status and catepath like '{$cateOBJ->catepath}%'";
		$data = Contents::find($default_find_string)->limitPage($page,$pagesize)->fetchPagination($pagination)->order('id desc')->get();
		$this->_view['param'] 		= $param_array;
		$this->_view['pagination']	= $pagination;
		$this->_view['data']      	= array(
			'fetch_data'=>$data,
			'context'=>$this->_context,
			'category'=>$cateOBJ
		);
	}

	function actionView()
	{
		$did = intval($this->_context->id);
		if (!$did) header('location:'.url('default'));
		# 获取详细信息
		$data = Contents::find('model = 1 and id = ?',$did)->getOne();
		if ($data->id())
		{ 
			$this->_view['data'] = $data;
		}else{
			return $this->_redirectMessage('出错啦!','没有找到您想要查找的信息',url('default'));
		}
	} 
}